/*
NinjaTrader Strategy of Strategy 1.13
Generated by StrategyQuant version 3.6.3
Generated at Sat Sep 06 21:09:00 GMT 2014
Tested on EURUSD_fhdb, D1, 01.11.2007 - 29.03.2013
Spread: 2.5, Slippage: 0.0, Min distance of stop from price: 5.0
*/
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Indicator;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Strategy;
#endregion
namespace NinjaTrader.Strategy
{
///
/// Enter the description of your strategy here
///
[Description("Enter the description of your strategy here")]
public class Strategy113 : SQManagedStrategy
{
#region Variables
// Wizard generated variables
// User defined variables (add any user defined variables below)
#endregion
///
/// This method is used to configure the strategy and is called once before any strategy method is called.
///
protected override void Initialize()
{
base.Initialize();
ReplacePendingOrders = true;
ExitOnClose = false;
MinimumPTSL = 30;
MaximumPTSL = 300;
PendingOrderValidOneBar = false;
BarsRequired = 120;
StrictStopPrices = true;
LimitSignalsToRange = false;
TimeRangeFrom = 0800;
TimeRangeTo = 1600;
MaxTradesPerDay = 0; // 0 means unlimited
}
///
/// Called on each bar update event (incoming tick)
///
protected override void OnBarUpdate()
{
// ------------------------------------------
// STRATEGY MANAGEMENT
// ------------------------------------------
if(Bars.FirstBarOfSession) tradesPerDay = 0;
// Stop/Limit order expiration handling
// Long --------
if(pendingEntryOrder != null && pendingEntryOrder.OrderAction == OrderAction.Buy) {
// Expiration
if(sqGetPendingOrderBars(pendingEntryOrder) >= 26) {
CancelOrder(pendingEntryOrder);
}
}
// Short --------
if(pendingEntryOrder != null && pendingEntryOrder.OrderAction == OrderAction.SellShort) {
// Expiration
if(sqGetPendingOrderBars(pendingEntryOrder) >= 26) {
CancelOrder(pendingEntryOrder);
}
}
// ------------------------------------------
// ENTRY RULES
// ------------------------------------------
tradeEntered = false;
if(sqCheckTimeWithinRange()) {
// Long --------
if(maxTradesPerDay == 0 || tradesPerDay < maxTradesPerDay) {
bool LongEntryCondition = (sqBBUp(94, 10, 0, 0) > sqKeltnerUp(34, 2.8, 0));
if(LongEntryCondition == true) {
double price = roundPrice(Ichimoku(Median, 6, 18, 38).TenkanSen[0] + (0.4) * (sqATR(96)));
sqEnterLongStop(price);
}
}
// Short --------
if(maxTradesPerDay == 0 || tradesPerDay < maxTradesPerDay) {
bool ShortEntryCondition = (sqBBDown(94, 10, 0, 0) < sqKeltnerDown(34, 2.8, 0));
if(ShortEntryCondition == true) {
double price = roundPrice(Ichimoku(Median, 6, 18, 38).TenkanSen[0] + (-0.4) * (sqATR(96)));
sqEnterShortStop(price);
}
}
}
// ------------------------------------------
// MANAGE TRADE & EXIT RULES
// ------------------------------------------
if(tradeEntered) {
// don't modify SL is new order was just placed
return;
}
IOrder slOrder = sqGetStopLossOrder();
double priceLevel;
// Long --------
// Exit After X Bars
if(Position.MarketPosition == MarketPosition.Long) {
if (BarsSinceEntry("Long") >= 37-1) {
sqExitLong("LongExitAfterXBars");
}
}
// Stop trailing
if(Position.MarketPosition == MarketPosition.Long) {
priceLevel = roundPrice(sqKeltnerMiddle(13, 4.2, 0) + (0.1) * (Math.Abs(Open[6] - sqKeltnerDown(43, 4.7, 0))));
if(priceLevel > 0) {
if(slOrder == null) {
sqSetLongSL(priceLevel);
} else {
if(slOrder.StopPrice == 0 || slOrder.StopPrice < priceLevel) {
sqSetLongSL(priceLevel);
}
}
}
}
// Short --------
if(Position.MarketPosition == MarketPosition.Short) {
// Exit After X Bars
if (BarsSinceEntry("Short") >= 37-1) {
sqExitShort("ShortExitAfterXBars");
}
}
// Stop trailing
if(Position.MarketPosition == MarketPosition.Short) {
priceLevel = roundPrice(sqKeltnerMiddle(13, 4.2, 0) + (-0.1) * (Math.Abs(Open[6] - sqKeltnerUp(43, 4.7, 0))));
if(priceLevel > 0) {
if(slOrder == null) {
sqSetShortSL(priceLevel);
} else {
if(slOrder.StopPrice == 0 || slOrder.StopPrice > priceLevel) {
sqSetShortSL(priceLevel);
}
}
}
}
}
override protected void sqDefineStopLoss(int direction) {
stopLoss.type = CalculationMode.Ticks;
if(direction == 1) {
// long
stopLoss.value = 35;
} else {
// short
stopLoss.value = 35;
}
}
override protected void sqDefineProfitTarget(int direction) {
profitTarget.type = CalculationMode.Ticks;
if(direction == 1) {
// long
profitTarget.value = 0;
} else {
// short
profitTarget.value = 0;
}
}
#region Properties
#endregion
}
}